using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using GenericRepository.EF;
using SeventhSenseSystems.HighFlyingPm.Business.Entities;
using SeventhSenseSystems.HighFlyingPm.Business.Impl.Dal;

namespace SeventhSenseSystems.HighFlyingPm.Business.Models
{ 
   #if	!INMEMREPO
	[Export(typeof (IProjectRepository))]
	#endif
	class ProjectRepository : Repository<HighFlyingPmModelContainer,Project>, IProjectRepository
	{
	   
	}

	#if INMEMREPO
	[Export(typeof (IProjectRepository))]
	#endif
	internal class InMemoryProjectRepository : IProjectRepository
	{
		private IList<Project> items = new List<Project>(); 

		public void Dispose()
		{
		   
		}

		public IQueryable<Project> All
		{
			get {return items.AsQueryable(); }
		}

		public IQueryable<Project> AllIncluding(params Expression<Func<Project, object>>[] includeProperties)
		{
			return items.AsQueryable();
		}

		public Project Find(params object[] keyValues)
		{
			var id = (Guid) keyValues[0];
			return items.First(i => i.Id == id);
		}

		public void Edit(Project entity)
		{
			Delete(entity);
			Add(entity);
		}

		public void Save()
		{
			return;
		}

		public void Add(Project entity)
		{
			items.Add(entity);
		}

		public void Delete(Project entity)
		{
			 items.Remove(items.First(i => i.Id == entity.Id));
		}

	}

	public interface IProjectRepository : IDisposable
	{
		IQueryable<Project> All { get; }
		IQueryable<Project> AllIncluding(params Expression<Func<Project, object>>[] includeProperties);
		Project Find(params object[] keyValues);
		void Delete(Project entity);
		void Add(Project entity);
		void Edit(Project entity);
		void Save();
	}
}